package com.nwpu.server.common.util;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @Author: YuXingZh
 * @Date: Created in 17:14 2021-11-03
 * @Description: 格式化工具
 */
public class FormatUtils {

    public static String formatFileSize(long fileS) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        String wrongSize = "0B";
        if (fileS == 0) {
            return wrongSize;
        }
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + " B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + " KB";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + " MB";
        } else {
            fileSizeString = df.format((double) fileS / 1073741824) + " GB";
        }
        return fileSizeString;
    }

    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    public static String getCurrentTime() {
        Date date = new Date();
        java.sql.Date sDate = new java.sql.Date(date.getTime());
        return sDate.toString();
    }
}
